<template>
	<view class="mine-page">
		<view class="top-box"
			:style="{background: `url(${baseImgUrl}images_bg1.png) no-repeat;background-size: cover`}">
			<view class="nav-bar" :style="{ height: navBarHeight }"></view>
			<view class="user-info">
				<view class="user-img">
					<!-- <image class="user-head" :src="avatar" mode="aspectFill" /> -->
					<image class="user-head" src="/static/images/acquiesce.jpg" mode="widthFix"></image>
				</view>
				<view class="info-box">
					<view class="user-name">
						<view class="name" v-if="roleType ===4">商家：{{ userInfo.storeName?userInfo.storeName:'微信用户' }}
						</view>
						<view class="name" v-if="roleType ===3">
							供应商：{{ userInfo.supplierName?userInfo.supplierName:'微信用户' }}
						</view>
						<view class="member"></view>
					</view>
					<view class="id">
						<text style="display: block;">用户名：{{ userInfo.name }} </text>
						<text>电话：{{userInfo.phoneNumber}}</text>
					</view>
				</view>
				<view class="setting-icon" @click="editUser">
					<image class="icon" :src="baseIconUrl + 'icon_setting.png'" mode="aspectFill" />
				</view>
			</view>
			<view class="order-box" v-if="roleType === 4">
				<view class="title-box">
					<view class="title">我的订单</view>
				</view>
				<view class="order-list">
					<view class="order-item" v-for="(item, index) in orderConfig" :key="index">
						<view class="icon-box" @click="clickOrderItem(item)">
							<image class="order-icon" :src="baseIconUrl + item.icon" mode="aspectFill" />
						</view>
						<view class="name">{{ item.name }}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="cell-box">
			<view class="cell-item" v-for="(item, index) in cellConfig" :key="index" @click="clickCellItem(item)">
				<view class="cell-icon">
					<image class="cell-img" :src="baseIconUrl + item.icon" mode="scaleToFill" />
				</view>
				<view class="name">{{ item.name }}</view>
				<view class="right-icon">
					<image class="arrow-img" :src="baseIconUrl + 'icon_right1.png'" mode="scaleToFill" />
				</view>
			</view>
		</view>
		<view class="tabBar">
			<view v-for="(item,index) in tabBerList" @click="clickPage(item.pagePath,index)"
				:style="{width:100 / tabBerList.length +'%'}">
				<image class="bar_img" v-if="tabBerActive===index" :src="item.selectedIconPath"></image>
				<image class="bar_img" :src="item.iconPath" v-else></image>
				<text>{{item.text}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		baseIconUrl,
		baseImgUrl
	} from '@/config'
	export default {
		name: 'UserCenter',

		data() {
			return {
				roleType: 3,
				tabBerActive: 1,
				tabBerList: [{
						"pagePath": "/subPages/otherPages/businessOrder",
						"iconPath": "/static/images/tabBar/tab_home.png",
						"selectedIconPath": "/static/images/tabBar/tab_home_active.png",
						"text": "首页"
					},
					{
						"pagePath": "/subPages/otherPages/privatelyOwned",
						"iconPath": "/static/images/tabBar/tab_mine.png",
						"selectedIconPath": "/static/images/tabBar/tab_mine_active.png",
						"text": "个人中心"
					}
				],
				baseIconUrl,
				baseImgUrl,
				navBarHeight: '',
				avatar: 'https://rb.biomedical-wh.com/prod-api/profile/upload/fangxiStatis/icons/icon_head.png',
				userInfo: {
					name: '微信用户',
					member: true,
					id: '无'
				},
				orderConfig: [{
						name: '销售订单',
						key: '',
						icon: 'icon_wait.png'
					},
					{
						name: '采购订单',
						key: '',
						icon: 'icon_take.png'
					}
				],
				cellConfig: [{
						name: '店铺管理',
						key: '',
						icon: 'icon_address.png',
						pageUrl: '/subPages/otherPages/components/shopManage'
					},
					{
						name: '商品管理',
						key: 2,
						icon: 'icon_privacy.png',
						pageUrl: '/subPages/otherPages/components/productManage'
					},
					{
						name: '关于我们',
						key: 1,
						icon: 'icon_about.png',
						pageUrl: '/subPages/otherPages/wxHtml?id=1'
					},
					{
						name: '隐私协议',
						key: 2,
						icon: 'icon_privacy.png',
						pageUrl: '/subPages/otherPages/wxHtml?id=2'
					}
				]
			}
		},

		onLoad() {
			this.navBarHeight = this.$store.getters.heightData.navBarHeight + 'px'
		},
		onShow() {

			this.getUserInfo()
		},
		methods: {
			clickPage(t, i) {
				if (this.roleType === 4) {
					uni.reLaunch({
						url: `/subPages/otherPages/businessOrder`
					});
				} else if (this.roleType === 3) {
					uni.reLaunch({
						url: `/subPages/otherPages/supplierOrder`
					});
				}

			},
			async getUserInfo() {
				const res = await this.$GET('/fx/user/getInfo')
				if (res.code == 200) {
					this.roleType = res.data.roleType
					console.log(res.data, 'js')
					this.userInfo.name = res.data.userName
					this.userInfo.phoneNumber = res.data.phoneNumber
					this.userInfo.storeName = res.data.storeName ? res.data.storeName : '无'
					this.userInfo.supplierName = res.data.supplierName ? res.data.supplierName : '无'
					// this.avatar = res.data.userPhoto.includes('http') ? res.data.userPhoto :
					// 	`${this.baseUrl}${res.data.userPhoto}`
				}
			},
			clickOrderItem(item) {
				uni.navigateTo({
					url: `/subPages/otherPages/businessOrder`
				})
			},
			clickCellItem(item) {
				uni.navigateTo({
					url: item.pageUrl
				})
			},
			editUser() {
				uni.navigateTo({
					url: "/subPages/userCenter/editUser"
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.top-box {

		// background: linear-gradient(to bottom, #2da884, #f2f2f2);
		.user-info {
			display: flex;
			padding: 20rpx 28rpx 40rpx;

			.user-img {
				width: 120rpx;
				height: 120rpx;
				border-radius: 60rpx;
				overflow: hidden;

				// background-color: #f4e2cc;
				.user-head {
					width: 100%;
					height: 100%;
				}
			}

			.info-box {
				flex: 1;
				margin: 0 20rpx;

				.user-name {
					display: flex;
					align-items: center;

					.name {
						margin-bottom: 14rpx;
						font-size: 36rpx;
						font-weight: 500;
						color: #FFF;
					}
				}

				.id {
					font-size: 24rpx;
					color: #FFF;
				}
			}

			.setting-icon {
				width: 48rpx;
				height: 48rpx;

				.icon {
					width: 100%;
					height: 100%;
				}
			}
		}

		.order-box {
			padding: 24rpx;
			margin: 0 28rpx;
			border-radius: 12rpx;
			background-color: #FFF;

			.title-box {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;

				.title {
					font-size: 30rpx;
					font-weight: 500;
				}

				.more {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: #999;

					.more-icon {
						width: 34rpx;
						height: 34rpx;
						margin-left: 10rpx;
					}
				}
			}

			.order-list {
				display: flex;
				justify-content: space-around;
				align-items: center;

				.order-item {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;

					.icon-box {
						width: 48rpx;
						height: 48rpx;

						.order-icon {
							width: 100%;
							height: 100%;
						}
					}

					.name {
						color: #999;
					}
				}
			}
		}
	}

	.cell-box {
		padding: 0 32rpx;
		margin: 20rpx 28rpx 0;
		border-radius: 12rpx;
		background-color: #FFF;

		.cell-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 122rpx;

			.cell-icon {
				width: 42rpx;
				height: 42rpx;

				.cell-img {
					width: 100%;
					height: 100%;
				}
			}

			.name {
				flex: 1;
				font-size: 30rpx;
				font-weight: 500;
				margin-left: 40rpx;
			}

			.right-icon {
				width: 42rpx;
				height: 42rpx;

				.arrow-img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.tabBar {
		position: fixed;
		bottom: 0;
		z-index: 9999;
		width: 100%;
		height: 120upx;
		background-color: #ffffff;
		display: flex;

		>view {
			text-align: center;

			>image {
				margin: 18upx auto 0;
				width: 55upx;
				height: 55upx;
			}

			text {
				font-size: 20upx;
				display: block;
			}
		}
	}
</style>